package com.smile.ye.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smile.ye.data.dto.StaffCreateDto;
import com.smile.ye.data.dto.StaffQueryDto;
import com.smile.ye.data.dto.StaffUpdateDto;
import com.smile.ye.data.entity.StaffEntity;
import com.smile.ye.mapper.StaffMapper;
import com.smile.ye.response.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StaffService {
    @Autowired
    StaffMapper mapper;

    public Result query(StaffQueryDto dto){
        IPage<StaffEntity> page = new Page<>(dto.getPage(),dto.getSize());
        mapper.selectPage(page,null);
        return  Result.build(page);
    }

    public Result create(StaffCreateDto dto){
        int i = mapper.insert(dto);
        if(i!=0) throw new RuntimeException("创建失败");
        return Result.build();
    }

    public Result update(String id,StaffUpdateDto dto){
        dto.setId(id);
        int i = mapper.updateById(dto);
        if(i ==0) throw new RuntimeException("更新失败");
        return Result.build();
    }
    public Result remove(String id){
        mapper.deleteById(id);
        return Result.build();
    }
}
